home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
julin105.zip
/
DOC
/
READ.ME
next >
Wrap
Text File
|
1993-08-02
|
15KB
|
390 lines
JULIAN DATE LIBRARY
v:1.05 d:08/02/93
Robert Emmons
CalcShop Inc.
P.O Box 1231
W. Caldwell, NJ 07007
Phones: (201)228-9139 or (800)466-3469
JULIAN DATE LIBRARY (c)Copyright 1992 by CalcShop Inc.
All rights reserved.
1.00 GENERAL:
JULIAN provides a library of date routines which are useful in financial
and other types of programs. The functions are written in C, and they
allow you to translate dates between the following formats:
Name Format Example
------ ---------------------------- -----------
Gregroian string "mm/dd/yy" 9/12/92
Gregorian string "mm/dd/yyyy" 9/12/1992
Gregorian struct{int month, day, year} 9, 12, 1992
Julian long julianday 727453
So, why would you want to do that? Well, programs like Lotus, FoxPro,
and dBASE store dates internally as Julian day numbers. This makes it
easy to do date arithmetic. You can calculate the number of days between
any two dates, the day of the week for a particular date, or the date of
the day which is some number of days in the future. Almost all date
calculations are easier to do when you work with Julian day numbers
instead of the more commonly seen Gregorian calendar dates and their
string representations. Consequently, well written programs store dates
internally as Julian day numbers, and only translate the dates to
Gregorian or string when they have to input or output them. If you use
our JULIAN library, your programs can do the same.
JULIAN numbers all days sequentially starting with 1/1/0001 A.D. as
Julian day number 1, and ending with 12/31/9999 A.D. as Julian day
number 3652059. As you may guess from the table above, 9/12/1992 is
Julian day number 727453.
Other systems use different days as day number 1:
System Day number 1 To Convert to FoxPro, Add
------- ------------- -------------------------
JULIAN 1/1/0001 A.D. 1721425
Astronomical 1/1/4713 B.C. 0
FoxPro 1/1/4713 B.C. 0
Lotus 1/1/1899 A.D. 2415918
Purists prefer the FoxPro definition because astronomers also define
1/1/4713 B.C. as day number 1. You can convert between systems by adding
or subtracting the constant shown in the table, as long as the specified
date is within the range over which the system is defined.
JULIAN is fully corrected for leap years which occur when the Gregorian
year is evenly divisable by 400, or when it is evenly divisable by 4 and
not by 100.
Calendar systems in the past were not as accurate ours. There were
several instances where the seasons got out of synchronism with the
dates predicted by the calendar. Consequently, dates were sometimes
changed arbitrarily. (Like "The King says this March will only have
18 days. March 18th will be immediately followed by April 1.").
Julian does not correct for these past arbitrary calendar changes.
There would seem to be no reason to make the corrections unless you
need dates for historical purposes before the year 1900.
2.00 REGISTRATION and TECHNICAL SUPPORT
The JULIAN library is not free. After you try it and decide to continue
to use it, you must pay the registration fee. See the registration form
at the end of this document.
Anyone can copy all the JULIAN DATE LIBRARY files, and distribute it
freely so others can try it before registering their copy.
We also do custom programming for investments, finance and accounting.
For technical support, questions or comments, call (201)228-9139 or
write to the address above. Please do not call for technical support on
the 800 line.
3.00 FILE LIST
The distribution disk contains 6 files:
JULIAN.C Source code for the library
JULDEF.H Definitions and prototypes
JULDEMO.C Source code showing use of JULIAN functions
JULDEMO.EXE Executable JULDEMO
READ.ME This file
REGISTER.DOC A program registration form
4.00 INSTALLATION
Make a directory and copy all the files into it from the distribution
disk. The information below and the source code from JULDEMO.C should
show you how to call the JULIAN library functions from your own C code.
You can use one of 2 methods to include the JULIAN library in your
programs. You can use your program editor to insert JULIAN.C into
your program file and compile and link the file to produce and
executable .EXE file. Alternatively, compile your program and JULIAN.C
separately. Then, when you link your program, link in JULIAN.OBJ, or
list JULIAN.OBJ in your project file.
5.00 USING JULDEMO
Switch to the appropriate directory and type JULDEMO. You will be
prompted for dates, and they will be conveted to and from Julian day
numbers, and displayed. See the source code in JULDEMO.C.
If you start JULDEMO by entering "juldemo a", the demo runs in
"automatic" mode. It will read, convert and display a preprogrammed set
of string representations of Gregorian dates.
6.00 DESCRIPTION OF THE JULIAN FUNCTIONS
See JULDEF.H for definitions and function prototypes.
The JULIAN library defines a Gregorian date type:
typedef struct gregorian
{
int month, day, year;
} GDATE;
There are just 2 main conversion functions in the JULIAN library:
Function Description
-------- -----------
long gregtojday(GDATE) converts a Gregorian date to a Julian day number
GDATE jdaytogreg(long) convetts a Julian day number to a Gregorian date
There are just 2 input/output functions in the JULIAN library:
Function Description
-------- -----------
GDATE mmddyyyytogreg( converts a string date to a Gregorian
char *str, structure
int nearyear
)
char *gregtommddyyyy( converts a Gregorian structure to a
char *str, date
GDATE gdate,
int nearyear
)
The other functions in the JULIAN library are called as subfunctions
from the main funcions above. Although you probably won't need them,
they are supplied just in case.
gregtojday() translates a Gregorian date between 1/1/0001 A.D and
12/31/9999 to a Julian day number between 1 and 3652059. Those of you
needing B.C. dates, consult your abacus.
gregtojear() translates a Gregorian date to a Julian pseudoyear. This is
a function which you probably won't need, but for you "Star Trek"
fans, a Julian pseudoyear is kind of like a "Star Date". It is a double
whose whole number part is almost always equal to the corresponding
Gregorian year, while its fractional part is approximately equal to the
corresponding year day divided by 365. The existence of leap years
prevents unconditional exact equality. The Julian pseudoyear is equal
one plus (the corresponding Julian day divided by the average number of
days in a year). The average number of days in a year takes into account
the full cycle of leap years over 4 centuries.
Here are some sample Julian pseudoyears:
Gregorian Julian Julian